package api

import (
	Tools2 "Wechat/Tools"
	"container/list"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func TestHelloWorld(c *gin.Context) {
	var testMap = make(map[string]interface{})
	c.BindJSON(&testMap)
	//str := testMap["str"].(string)
	c.JSON(http.StatusOK, gin.H{
		"msg": "ok",
		"str": "Hello",
	})
}

func TestList(c *gin.Context) {
	isOk, actArr := activityservice.GetListActivity(0)
	if !isOk {
		return
	}
	var List list.List
	for _, value := range actArr {
		List.PushBack(value)
	}
	for start := List.Front(); start != nil; start = start.Next() {
		fmt.Println(start.Value)
	}
	var res = make(map[string]interface{})
	res["msg"] = "ok"
	res["data"] = actArr
	c.JSON(http.StatusOK, res)
}

// 测试富文本的传输
func TestHtml(c *gin.Context) {
	// 获取数据
	id := c.DefaultPostForm("id", "")
	content := c.DefaultPostForm("content", "")
	title := c.DefaultPostForm("title", "")
	fmt.Println("id : ", id)
	fmt.Println("title : ", title)
	fmt.Println("content : ", content)
	c.JSON(http.StatusOK, gin.H{
		"msg":     http.StatusText(http.StatusOK),
		"id":      id,
		"title":   title,
		"content": content,
	})
}

// 存储富文本的图片
func TestHtmlPic(c *gin.Context) {
	pic, err := c.FormFile("img")
	Tools2.CherrError(err, "Get rich-text picture ERROR!")
	filepath := "./Picture/RichText/" + pic.Filename
	err = c.SaveUploadedFile(pic, filepath)
	Tools2.CherrError(err, "SaveUploadedFile ERROR!")
}
